import json


def refrish_config(
    time_range="",
    code="",
    start_date="",
    end_date="",
    interval_reflash_speed="",
):
    with open(r"config_live.json", mode="r") as f:
        res = f.read()
    dic = json.loads(res)

    if time_range == "" or time_range == None:
        time_range = dic["Dropdown_pre"]
    if code == "" or code == None:
        time_range = dic["Input_code"]
    if start_date == "" or start_date == None:
        start_date = dic["start_date"]

    if interval_reflash_speed == "" or interval_reflash_speed == None:
        if time_range != "" or time_range != None:
            interval_reflash_speed = int(time_range) * 60 * 2000
        else:
            interval_reflash_speed = dic["interval_reflash_speed"]

    updating_code_list = dic["updating_code_list"]
    updating_code_list.append(code)
    temp_codeL = []
    T = 0

    for codes in updating_code_list:
        if codes not in temp_codeL:
            temp_codeL.append(codes)
            if T >= 6:
                break
            T += 1

    dic = {
        "Dropdown_pre": time_range,
        "Input_code": code,
        "start_date": start_date,
        "interval_reflash_speed": interval_reflash_speed,
        "updating_code_list": temp_codeL,
    }
    with open(r"config_live.json", mode="w") as f:
        f.write(json.dumps(dic))